package com.dede.dreamserver

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    private val TAG = "MainActivity"

    @SuppressLint("PrivateApi")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

//        try {
//            val dreamServer = TestDreamServer()
//            val field = DreamService::class.java.getDeclaredField("mSandman")
//            field.isAccessible = true
//            val iDreamManager = field.get(dreamServer)
//            val method = iDreamManager.javaClass.getMethod("dream")
//            method.invoke(iDreamManager)
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }

        tv_test.setOnClickListener {
            //            val intent = Intent(this, TestDreamServer::class.java)
//            intent.action = "android.service.dreams.DreamService"
//            bindService(intent, object : ServiceConnection {
//                override fun onServiceDisconnected(name: ComponentName?) {
//                }
//
//                override fun onServiceConnected(name: ComponentName?, service: IBinder) {
////                    Log.i(TAG, "onServiceConnected: " + service.javaClass.name)
//                    val callBackClazz = Class.forName("android.os.IRemoteCallback")
//
//                    val method = service.javaClass.getMethod("attach", IBinder::class.java, Boolean::class.java, callBackClazz)
//                    method.invoke(service, window.attributes.token, false, null)
//                }
//            }, Context.BIND_AUTO_CREATE)
        }
    }
}
